<template>
    <el-skeleton :loading="loading" animated :throttle="500">
      <template #template>
        <div class="tt" v-for="o in 4" :key="o">
          <el-skeleton-item
            variant="image"
            style="width: 240px; height: 240px"
          />
          <div style="padding: 14px">
            <div
              style="
                display: flex;
                align-items: center;
                justify-items: space-between;
                margin-top: 5px;
                height: 16px;
              "
            >
              <el-skeleton-item variant="text" style="margin-right: 16px" />
              <el-skeleton-item variant="text" style="width: 30%" />
            </div>
          </div>
        </div>
      </template>
      <template #default>
        <el-row>
          <el-empty :description="description" />
          <el-col :span="6" v-for="musicData in musicData" :key="musicData">
            <div class="grid-content bg-purple">
              <router-link
                :to="{ path: '/itemMusic', query: { id: musicData.id } }"
              >
                <el-card :body-style="{ padding: '0px' }" class="resource_div">
                  <img :src="musicData.picUrl" class="image" />
                  <span>{{ musicData.name }}</span>
                  <p>{{ changCount(musicData.playCount) }}</p>
                  <svg class="icon bofang" aria-hidden="true">
                    <use xlink:href="#icon-bofang"></use>
                  </svg>
                </el-card>
              </router-link>
            </div>
          </el-col>
        </el-row>
      </template>
    </el-skeleton>
</template>

<script>
import { reactive, onMounted, getCurrentInstance } from "vue";
import { get } from "../../request/Home/App_resData";
import "../../../public/font_3743019_fzljx6cqx56/iconfont";
import { mapMutations, mapState, useStore } from "vuex";
import { ElMessage } from "element-plus";
export default {
  data() {
    return {
      loading: true,
      description: false,
    };
  },
  computed: {
    ...mapState(["musicData"]),
  },
  setup() {
    const store = useStore();
    onMounted(async () => {
      let dataS = getCurrentInstance().data;
      let resource = await get("/personalized?limit=20");
      if (resource.data.code == 200) {
        store.state.musicData = resource.data.result;
        dataS.loading = false
      } else {
        dataS.description = true;
        ElMessage({
          message: "网络错误",
          grouping: true,
          type: "error",
        });
      }
    });
  },
  methods: {
    changCount: function (num) {
      if (num >= 100000000) {
        return (num / 100000000).toFixed(1) + "亿";
      } else if (num < 100000000 && num >= 100000) {
        return (num / 100000).toFixed(1) + "万";
      }
    },
  },
  watch: {
    musicData: function (to) {
      if (to) {
        this.description = false;
      } else {
        this.description = true;
      }
    },
  },
};
</script>

<style lang="less" scoped>
.icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
.el-row {
  position: relative;
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
  .el-empty {
    position: absolute;
    left: 40%;
    top: 50%;
  }
}
.el-skeleton {
  display: flex;
  justify-content: space-around;
  margin: 5px;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.resource_div {
  position: relative;
  height: 269px;
  margin: 10px;
  cursor: pointer;

  div {
    img {
      width: 100%;
      display: block;
    }
    span {
      display: inline-block;
      height: 25px;
      line-height: 14px;
      font-size: 13px;
      font-weight: 200;
    }
  }

  p {
    position: absolute;
    width: 80px;
    top: -6px;
    right: -12px;
    color: #fffff8;
  }

  .bofang {
    position: absolute;
    top: 150px;
    left: 8px;
    font-size: 30px;
    color: #fffff8;
  }
}
</style>
